<template>
  <div class="app-container">
    <el-card style="width: 100%">
      <el-row
        style="margin: 5px 0px"
        type="flex"
        justify="space-around">
        <el-col :span="12">
          <span style="margin-right: 20px;">
            产品编号：{{ product_no }}
          </span>
          <el-button
            type="primary"
            size="medium"
            icon="el-icon-s-promotion"
            @click="handleTransferAction">
            在线调用
          </el-button>
        </el-col>
        <el-col
          :span="12"
          style="text-align: right"></el-col>
      </el-row>
      <el-table
        border
        :data="productListData"
        stripe
        size="small"
        v-loading="loading"
        style="width: 100%; margin-bottom: 3px">
        <el-table-column
          prop="id"
          label="序号"
          width="80"></el-table-column>
        <el-table-column
          prop="phone"
          label="号码"
          min-width="120"></el-table-column>
        <el-table-column
          v-if="is_encrypt"
          prop="encrypt_mask"
          label="加密方式"
          min-width="120"></el-table-column>
        <el-table-column
          prop="message"
          label="描述"
          min-width="120"></el-table-column>
        <el-table-column
          prop="origin_msg"
          label="结果"
          min-width="120"></el-table-column>
        <el-table-column
          prop="is_charge"
          label="收费"
          min-width="120">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.is_charge == 1" type="success">扣费</el-tag>
            <el-tag v-else type="danger">不扣费</el-tag>
          </template>  
        </el-table-column>
        <el-table-column
          prop="user.nick_name"
          label="用户"
          min-width="120"></el-table-column>
        <el-table-column
          prop="created_at"
          label="创建时间"
          min-width="180"></el-table-column>
      </el-table>
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="currentPage"
        :page-sizes="[10, 20, 30, 40]"
        :page-size="pageSize"
        layout="total,sizes, prev, pager, next, jumper, slot"
        :total="total">
        <span style="line-height: 28px; margin-left: 5px">
          <el-button
            type="text"
            @click="refreshAction"
            :loading="loading">
            {{ loading ? '' : '刷新' }}
          </el-button>
        </span>
      </el-pagination>
    </el-card>
  </div>
</template>
<script>
import Transfer from '@/views/product/operator/onlineState/transfer';
import Detail from '@/views/product/operator/onlineState/detail';
import { onlineStateGetList } from '@/api/product';
export default {
  name:"list",
  props: {
    product_no: {
      type: [String, Number],
      default: '',
    },
    is_encrypt:{
      type:Boolean,
      default: false
    }
  },
  data(){
    return {
      productListData: [],
      pageSize: 10,
      currentPage: 1,
      loading: false,
      total: 0,
    }
  },
  created(){
    this.getListData()
  },
  computed:{
    searchConditions(){
      return {
        user_id: this.$store.state.user.info.id,
        product_no: this.product_no
      }
    }
  },
  methods:{
    handleTransferAction(){
      this.showTransferAction()
    },
    showTransferAction(){
      this.$createDialog({
        title: '在线调用',
        component: Transfer,
        width:"40%",
        props: {
          productNo: this.product_no,
          is_encrypt: this.is_encrypt
        },
        buttons: [{ text: '提交', callback: 'handleSubmit', name: 'submit' }],
      });
    },
    refreshAction() {
      this.$set(this, 'currentPage', 1);
      this.$set(this, 'pageSize', 10);
      this.getListData();
    },
    handleSizeChange(val) {
      this.$set(this, 'currentPage', 1);
      this.$set(this, 'pageSize', val);
      this.getListData();
    },
    handleCurrentChange(val) {
      this.$set(this, 'currentPage', val);
      this.getListData();
    },
    getListData(){
      this.loading = true;
      onlineStateGetList({ page: this.currentPage, limit: this.pageSize, where: this.searchConditions }).then(res => {
        this.$set(this, 'productListData', res.data.data);
        this.$set(this, 'total', res.data.total);
        this.loading = false;
      });
    },
    showDetailAction(row){
      this.$createDialog({
        title: '详情',
        component: Detail,
        width:"40%",
        props: {
          formData: row,
          is_encrypt: this.is_encrypt
        },
        buttons: [{ text: '关闭', callback: 'handleSubmit', name: 'submit' }],
      });
    }
  }
}
</script>